﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Track
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Map;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem
{
  public sealed class Track : ILocatable<Track>
  {
    [CachedData]
    private int _locatorNodeIndex;
    [SaveableField(117)]
    private Track _nextLocatable;
    [SaveableField(0)]
    public Vec2 Position;
    [SaveableField(1)]
    public float Direction;
    [SaveableField(10)]
    public TextObject PartyName;
    [SaveableField(20)]
    public CultureObject Culture;
    [SaveableField(30)]
    public float Speed;
    [SaveableField(40)]
    public int NumberOfAllMembers;
    [SaveableField(50)]
    public int NumberOfHealthyMembers;
    [SaveableField(60)]
    public int NumberOfMenWithHorse;
    [SaveableField(70)]
    public int NumberOfMenWithoutHorse;
    [SaveableField(80)]
    public int NumberOfPackAnimals;
    [SaveableField(90)]
    public int NumberOfPrisoners;
    [SaveableField(100)]
    public CampaignTime CreationTime;
    [SaveableField(140)]
    public float Life;
    [SaveableField(150)]
    public Track.PartyTypeEnum PartyType;

    internal static void AutoGeneratedStaticCollectObjectsTrack(
      object o,
      List<object> collectedObjects)
    {
      ((Track) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    private void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      collectedObjects.Add((object) this.PartyName);
      collectedObjects.Add((object) this.Culture);
      CampaignTime.AutoGeneratedStaticCollectObjectsCampaignTime((object) this.CreationTime, collectedObjects);
      collectedObjects.Add((object) this._nextLocatable);
    }

    internal static object AutoGeneratedGetMemberValueIsDetected(object o)
    {
      return (object) ((Track) o).IsDetected;
    }

    internal static object AutoGeneratedGetMemberValueIsPointer(object o)
    {
      return (object) ((Track) o).IsPointer;
    }

    internal static object AutoGeneratedGetMemberValueIsEnemy(object o)
    {
      return (object) ((Track) o).IsEnemy;
    }

    internal static object AutoGeneratedGetMemberValuePosition(object o)
    {
      return (object) ((Track) o).Position;
    }

    internal static object AutoGeneratedGetMemberValueDirection(object o)
    {
      return (object) ((Track) o).Direction;
    }

    internal static object AutoGeneratedGetMemberValuePartyName(object o)
    {
      return (object) ((Track) o).PartyName;
    }

    internal static object AutoGeneratedGetMemberValueCulture(object o)
    {
      return (object) ((Track) o).Culture;
    }

    internal static object AutoGeneratedGetMemberValueSpeed(object o) => (object) ((Track) o).Speed;

    internal static object AutoGeneratedGetMemberValueNumberOfAllMembers(object o)
    {
      return (object) ((Track) o).NumberOfAllMembers;
    }

    internal static object AutoGeneratedGetMemberValueNumberOfHealthyMembers(object o)
    {
      return (object) ((Track) o).NumberOfHealthyMembers;
    }

    internal static object AutoGeneratedGetMemberValueNumberOfMenWithHorse(object o)
    {
      return (object) ((Track) o).NumberOfMenWithHorse;
    }

    internal static object AutoGeneratedGetMemberValueNumberOfMenWithoutHorse(object o)
    {
      return (object) ((Track) o).NumberOfMenWithoutHorse;
    }

    internal static object AutoGeneratedGetMemberValueNumberOfPackAnimals(object o)
    {
      return (object) ((Track) o).NumberOfPackAnimals;
    }

    internal static object AutoGeneratedGetMemberValueNumberOfPrisoners(object o)
    {
      return (object) ((Track) o).NumberOfPrisoners;
    }

    internal static object AutoGeneratedGetMemberValueCreationTime(object o)
    {
      return (object) ((Track) o).CreationTime;
    }

    internal static object AutoGeneratedGetMemberValueLife(object o) => (object) ((Track) o).Life;

    internal static object AutoGeneratedGetMemberValuePartyType(object o)
    {
      return (object) ((Track) o).PartyType;
    }

    internal static object AutoGeneratedGetMemberValue_nextLocatable(object o)
    {
      return (object) ((Track) o)._nextLocatable;
    }

    public Vec2 GetPosition2D => this.Position;

    int ILocatable<Track>.LocatorNodeIndex
    {
      get => this._locatorNodeIndex;
      set => this._locatorNodeIndex = value;
    }

    Track ILocatable<Track>.NextLocatable
    {
      get => this._nextLocatable;
      set => this._nextLocatable = value;
    }

    public static Track.PartyTypeEnum GetPartyTypeEnum(MobileParty party)
    {
      if (party.IsBandit)
        return Track.PartyTypeEnum.Bandit;
      if (party.IsVillager)
        return Track.PartyTypeEnum.Villager;
      if (party.IsCaravan)
        return Track.PartyTypeEnum.Caravan;
      return party.IsLordParty ? Track.PartyTypeEnum.Lord : Track.PartyTypeEnum.Default;
    }

    public int Size => this.NumberOfAllMembers + this.NumberOfPrisoners;

    [SaveableProperty(110)]
    public bool IsDetected { get; set; }

    [SaveableProperty(120)]
    public bool IsPointer { get; set; }

    [SaveableProperty(130)]
    public bool IsEnemy { get; set; }

    public bool IsExpired => (double) this.CreationTime.ElapsedHoursUntilNow > (double) this.Life;

    public bool IsAlive => !this.IsExpired;

    public float Scale => Campaign.Current.Models.MapTrackModel.GetTrackScale(this);

    public Track() => this.Reset();

    public void Reset()
    {
      this.PartyName = TextObject.Empty;
      this.Culture = (CultureObject) null;
      this._locatorNodeIndex = -1;
      this._nextLocatable = (Track) null;
    }

    [LoadInitializationCallback]
    private void OnLoad() => this._locatorNodeIndex = -1;

    public enum PartyTypeEnum
    {
      Default,
      Lord,
      Bandit,
      Villager,
      GarrisonParty,
      PartyTypesCount,
      Caravan,
    }
  }
}
